package abc.demo2;

import java.util.concurrent.locks.Condition;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2022-12-28
 * Time: 14:37
 */

public class Main {

    public static void main(String[] args) {
        //循环打印4次
        AwaitSignal awaitSignal = new AwaitSignal(4);

        Condition a = awaitSignal.newCondition();
        Condition b = awaitSignal.newCondition();
        Condition c = awaitSignal.newCondition();

        new Thread(()->{
            awaitSignal.print("a",a,b);
        },"t1").start();

        new Thread(()->{
            awaitSignal.print("b",b,c);
        },"t2").start();

        new Thread(()->{
            awaitSignal.print("c",c,a);
        },"t3").start();

        //等待1s钟之后
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        awaitSignal.lock();
        try {
            a.signal();
        }finally {
            awaitSignal.unlock();
        }
    }
}
